refactor: consolidate Redis config, validators, tests, and serializer logic#63
Merged
RandomProgramm3r merged 4 commits intomainfrom Jul 25, 2025
Merged
refactor: consolidate Redis config, validators, tests, and serializer logic#63RandomProgramm3r merged 4 commits intomainfrom
RandomProgramm3r merged 4 commits intomainfrom
Conversation
This commit refactors the Redis connection settings to use distinct `REDIS_HOST` and `REDIS_PORT` environment variables instead of a single `REDIS_URL`. This change improves configuration clarity and flexibility across environments. Additionally, it removes an incorrect custom `save` method from the `User` model. The previous implementation improperly set the `last_login` field upon user creation. This logic is flawed, as the `last_login` field should be managed by Django's authentication backend during the actual login process.
The `validators.py` file, containing user-related validation logic, has been moved from the core project directory to the `user` application directory.
This commit introduces a new test suite for the password validation logic in `user/validators.py`. The tests cover all existing validator classes: - `UppercaseValidator` - `LowercaseValidator` - `NumericValidator` - `SpecialCharacterValidator` - `AsciiValidator` Each validator is tested for successful validation, failure cases with appropriate error messages, and correct help text generation. This ensures the reliability and correctness of the password validation system.
This commit introduces several refactoring improvements across the codebase to enhance clarity, remove redundancy, and simplify complex logic. Key changes include: - **PromoManager:** Simplified the filtering logic for promo codes by restructuring the query conditions for age and country, making it more readable. - **Promo Model:** Streamlined property methods (`is_available`, `get_available_unique_codes`) for better readability and consistency. - **Serializers (`business`, `core`, `user`):** - Removed unnecessary validation checks that are already handled by Django Rest Framework's default behavior (e.g., required fields). - Simplified complex conditional logic and improved handling of query parameters (`MultiCountryField`). - Made user-context checks in `BaseUserPromoSerializer` more direct and less defensive, assuming an authenticated request context. - **Settings:** Updated paths for password validators to reflect their new location in the `user` application.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit groups several improvements and refactorings across the project:
Redis Configuration
REDIS_URLvariable with distinctREDIS_HOSTandREDIS_PORTenvironment variables for clearer, more flexible setup across environments.savemethod on theUsermodel that improperly setlast_login; rely on Django’s authentication backend to manage this field.Validators
validators.py(user-related validation logic) from the core project directory into theuserapplication for better modularization and discoverability.Tests
user/validators.pycovering:UppercaseValidatorLowercaseValidatorNumericValidatorSpecialCharacterValidatorAsciiValidatorSerializers & Manager Logic
PromoManagerfiltering by restructuring age and country query conditions.Promomodel properties (is_available,get_available_unique_codes) for readability and consistency.business,core,user) to remove redundant validations already handled by DRF, simplify complex conditionals (e.g.,MultiCountryField), and assume authenticated context inBaseUserPromoSerializer.userapp.